package com.jxpanda.spring.module.pay.core.client;


import com.jxpanda.infrastructure.core.tollkit.ReflectionKit;

import java.util.HashMap;
import java.util.Map;

public class ReactivePaymentClientFactory {

    private final Map<String, ReactivePaymentClient> clientsWithAppName;
    private final Map<String, ReactivePaymentClient> clientsWithAppId;

    public ReactivePaymentClientFactory() {
        this.clientsWithAppName = new HashMap<>(4);
        this.clientsWithAppId = new HashMap<>(4);
    }


    <C extends ReactivePaymentClient> void addClient(C c) {
        this.clientsWithAppName.put(c.getAppName(), c);
        this.clientsWithAppId.put(c.getAppId(), c);
    }

    <C extends ReactivePaymentClient> C getClientByName(String appName) {
        return ReflectionKit.cast(this.clientsWithAppName.get(appName));
    }

    <C extends ReactivePaymentClient> C getClientByAppId(String appId) {
        return ReflectionKit.cast(this.clientsWithAppId.get(appId));
    }

}
